package com.jhw.ymcc.service.impl;

import com.jhw.ymcc.service.ICommonService;
import com.jhw.ymcc.util.StrUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author jhw
 * @create 2022/10/15
 */
@Service
public class CommonServiceImpl implements ICommonService {

    private String redisOrderToken = "orderToken:%s:%s";

    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    @Override
    public String createToken(String courseIds) {
        String token = StrUtils.getRandomString(8);
        Long loginId = 3L;
        String rediskey = String.format(redisOrderToken, loginId, courseIds);
        redisTemplate.opsForValue().set(rediskey, token, 30000, TimeUnit.MILLISECONDS);
        return token;
    }
}
